from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains

d = webdriver.Chrome()
d.maximize_window()  #最大化窗口
d.get("https://www.baidu.com")
time.sleep(1)

# 悬停设置
more_ele = d.find_element(By.CSS_SELECTOR, '[id="s-usersetting-top"]')
ActionChains(d).move_to_element(more_ele).perform()
time.sleep(1)

# 点击搜索设置
sousuoshezhi = d.find_element(By.LINK_TEXT,'搜索设置')
sousuoshezhi.click()
time.sleep(1)

# 点击保存设置
save_like = d.find_element(By.LINK_TEXT, '保存设置')
save_like.click()
time.sleep(1)
# 警告框处理 switch_to.alert
msg = d.switch_to.alert.text # 获取警告框的文本
# d.switch_to.alert.dismiss() # 关闭警告框
d.switch_to.alert.accept() # 确认警告框
print(msg)
